// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue';
import store from './store';
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import Router from 'vue-router';
import App from './App.vue';
import 'font-awesome/css/font-awesome.min.css';
import router from "./router";
import VCharts from 'v-charts'
import echarts from 'echarts';
import axios from 'axios';

// axios.defaults.retry = 4;
axios.defaults.retryDelay = 1000;
axios.defaults.timeout =  10000*60*60*24;

axios.interceptors.response.use(undefined, function axiosRetryInterceptor(err) {
    var config = err.config;
    // If config does not exist or the retry option is not set, reject
    if(!config || !config.retry) return Promise.reject(err);
    
    // Set the variable for keeping track of the retry count
    config.__retryCount = config.__retryCount || 0;
    
    // Check if we've maxed out the total number of retries
    if(config.__retryCount >= config.retry) {
        // Reject with the error
        return Promise.reject(err);
    }
    
    // Increase the retry count
    config.__retryCount += 1;
    
    // Create new promise to handle exponential backoff
    var backoff = new Promise(function(resolve) {
        setTimeout(function() {
            resolve();
        }, config.retryDelay || 1);
    });
    
    // Return the promise in which recalls axios to retry the request
    return backoff.then(function() {
        return axios(config);
    });
});



Vue.use(ElementUI);
Vue.use(Router);
Vue.use(VCharts);

Vue.prototype.$echarts = echarts
Vue.prototype.$axios = axios;

Vue.config.productionTip = false
 /**
  * 判断当前是否登录，未登录不能跳转路由
  * 防止未登录状态下直接输入路由跳转
  */
/* eslint-disable no-new */
// router.beforeEach((to, from, next) => {
//     if (to.path == '/login') {
//         sessionStorage.removeItem('user');
//     }
//     let user = JSON.parse(sessionStorage.getItem('user'));
//     if (!user && to.path != '/login') {
//         next({
//             path: '/login'
//         });
//     } else {
//         next();
//     }
// });

// 引入路由
new Vue({
    el: '#app',
    store,
    router, // 注入到根实例中
    render: h => h(App)
});